package com.ymatou.iapi.csim.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.csim.parameter.GetAutoReplyBean;
import com.ymatou.iapi.csim.service.GetAutoReplyCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.ymt_autoreply;
import com.ymttest.database.sqlwapper.CSIM.ymt_autoreplyWapper;
/**
*更新自动回复
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetAutoReply{
	private static GetAutoReplyBean bean;
	private static GetAutoReplyCall call;
	ymt_autoreplyWapper autoreplyWapper=new ymt_autoreplyWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("更新自动回复");
	}

	@Before
	public void caseUp() {
		bean=new GetAutoReplyBean();
		call=new GetAutoReplyCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetAutoReply_001() {
		Logger.start(true,"更新自动回复-买家客服");
		try {
			bean.setCSType(0);//客服类型 0 买家客服 1 买手客服
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatus(), "验证Status");
			Logger.verifyEquals("", call.getMsg(), "验证Msg");
			Map<String,Object> map=new HashMap();
			map.put("cstype", bean.getCSType());
			List<ymt_autoreply>  autoList=autoreplyWapper.selectby(map);
			for(int i=0;i<autoList.size();i++)
			{
				Logger.verifyEquals(autoList.get(i).getCSType(), new JSONObject(call.getResult().get(i).toString()).getInt("CSType"), "验证ymt_autoreply表中的CSType字段");
				Logger.verifyEquals(autoList.get(i).getType(), new JSONObject(call.getResult().get(i).toString()).getInt("Type"), "验证ymt_autoreply表中的CSType字段");
				Logger.verifyEquals(autoList.get(i).getMessage(), new JSONObject(call.getResult().get(i).toString()).getString("Message"), "验证ymt_autoreply表中的CSType字段");
			}
	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetAutoReply_002() {
		Logger.start(true,"更新自动回复-买手客服");
		try {
			bean.setCSType(1);//客服类型 0 买家客服 1 买手客服
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatus(), "验证Status");
			Logger.verifyEquals("", call.getMsg(), "验证Msg");
			Map<String,Object> map=new HashMap();
			map.put("cstype", bean.getCSType());
			List<ymt_autoreply>  autoList=autoreplyWapper.selectby(map);
			for(int i=0;i<autoList.size();i++)
			{
				Logger.verifyEquals(autoList.get(i).getCSType(), new JSONObject(call.getResult().get(i).toString()).getInt("CSType"), "验证ymt_autoreply表中的CSType字段");
				Logger.verifyEquals(autoList.get(i).getType(), new JSONObject(call.getResult().get(i).toString()).getInt("Type"), "验证ymt_autoreply表中的CSType字段");
				Logger.verifyEquals(autoList.get(i).getMessage(), new JSONObject(call.getResult().get(i).toString()).getString("Message"), "验证ymt_autoreply表中的CSType字段");
			}
	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}